package com.e.dianshang.controller;

import com.e.dianshang.service.HotSearchService;
import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;

/**
 * @author 陈静
 * @date 2020/11/11 19:06
 */
@RestController
@Api(value = "热门搜索",tags = "热门搜索接口的api")
public class HotSearchController {
    @Resource
    HotSearchService hotSearchService;
    @PostMapping("/topSearch")
    @ApiOperation(value = "热门搜索的接口")
    public Map topSerch(){
        JsonResult jsonResult = new JsonResult();
        String  ZSET = "topSearch";
        /**
         * 从高到低的排序集中获取从头(start)到尾(end)内的元素。
         * @param start 0 表示第一个
         * @param end  -1 表示最后
         * @return
         */
        Set<Object> searchs = hotSearchService.reverseRange(ZSET, 0, 2);
        if(searchs !=null){
            jsonResult.setCode("200");
            jsonResult.setMsg("success");
            jsonResult.put("searchs",searchs);
        }
        return jsonResult.getValues();



    }
}
